<template>
	
	<view class="wrap">
		<u-notice-bar type="error" mode="horizontal" :list="list"></u-notice-bar>
		<u-toast ref="uToast" />
		<view class="user">
			<view>
				<u-avatar size="100" :src="model.ava"></u-avatar>
			</view>
			<view class="name">
				<view style="font-size: 40rpx;">{{model.name}}
					<u-icon v-if="model.gender == '男'" size="40" name="../../../static/boy.png"></u-icon>
					<u-icon v-if="model.gender == '女'" size="40" name="../../../static/girl.png"></u-icon>
				</view>
				<view style="color: #a5a7a7;">{{model.identity}}</view>

			</view>
		</view>
		<u-gap height="20" bg-color="#eeeeee"></u-gap>
		<view class="info">
			<view class="input">
				<u-input v-model="model.content" placeholder="请输入约拍理由" :type="type" :border="border" :height="height" :auto-height="autoHeight" />
			</view>
			<u-line color="#eeeeee" />
			<view style="display: flex;align-items: center;padding: 20rpx;">
				<view>
					<u-icon size="50" name="../../../static/mes.png"></u-icon>
				</view>
				<view style="margin-left: 20rpx;color: coral;">
					我的联系方式，对方将会看到
				</view>
			</view>
			<u-line color="#eeeeee" />
			<view style="display: flex;align-items: center;padding: 20rpx;">
				<view>
					<u-icon size="50" name="../../../static/con.png"></u-icon>
				</view>
				<view style="margin-left: 20rpx;display: flex;align-items: center;">
					手机号:
					<u-input :value="model.phone" v-model="model.phone" type="number" />
				</view>
			</view>
			<u-line color="#eeeeee" />
			<view style="display: flex;align-items: center;padding: 20rpx;">
				<view>
					<u-icon size="50" name="../../../static/con.png"></u-icon>
				</view>
				<view style="margin-left: 20rpx;display: flex;align-items: center;">
					微信号:<u-input type="text" :value="model.wechat" v-model="model.wechat" />
				</view>
			</view>
			<u-line color="#eeeeee" />
			<view style="display: flex;align-items: center;padding: 20rpx;">
				<view>
					<u-icon size="50" name="../../../static/con.png"></u-icon>
				</view>
				<view style="margin-left: 20rpx;display: flex;align-items: center;">
					QQ号:<u-input type="number" :value="model.qq" v-model="model.qq" />
				</view>
			</view>
			<u-line color="#eeeeee" />
		</view>
		
		<view class="submit" @click="submit">
			<view class="text">提交约拍请求(将消耗1积分)</view>
		</view>
	</view>
</template>

<script>
	import api from '@/api/api.js'
	export default {
		data() {
			return {
				id: '',
				u_id:'',
				src: 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg',
				value: '',
				type: 'textarea',
				border: false,
				height: 100,
				autoHeight: true,
				model: {
					content: '',
					name: '',
					ava: '',
					gender: '',
					identity: '',
					phone: '',
					wechat: '',
					qq: ''
				},
				list:[
				   '安全提醒：切勿独自与陌生人在室内约拍！！！谨防上当受骗！！！'
				],
				m_name: '',
				m_ava: '',
				m_gender:'',
				m_id:''
			}
		},
		onLoad(res) {
			this.model.name = res.name;
			this.model.ava = res.ava;
			this.model.gender = res.gender;
			this.model.identity = res.identity;
			this.id = res.id;
			this.u_id = res.u_id;
		},
		onShow() {
			this.init();
		},
		methods: {
			init() {
				uni.getStorage({
					key: 'userinfo',
					success: (res) => {
						this.model.phone = res.data.phone;
						this.model.wechat = res.data.wechat;
						this.model.qq = res.data.qq;
						this.m_name = res.data.nickName;
						this.m_ava = res.data.avatarUrl
						this.m_gender = res.data.gender
						this.m_id = res.data.openid
					},
					fail: (res) => {
						uni.showToast({
							title: '请登录后操作！',
						})
						uni.navigateTo({
							url: '../user/login'
						})
					}
				})
			},
			submit() {
				//console.log(this.model)
				if (this.model.content == '') {
					this.$refs.uToast.show({
						title: '内容不能为空',
						type: 'error'
					})
				}else if(this.model.phone==undefined || this.model.qq==undefined || this.model.wechat==undefined){
					this.$refs.uToast.show({
						title: '请至少填写一种联系方式',
						type: 'error'
					})
				}else{
					uni.request({
						url:api.baseUrl+'/subY',
						method:'POST',
						data:{
							id:this.id,
							u_id:this.u_id,
							u_ava:this.model.ava,
							u_name:this.model.name,
							u_gender:this.model.gender,
							u_identity:this.model.identity,
							m_id:this.m_id,
							m_name:this.m_name,
							m_ava:this.m_ava,
							m_gender:this.m_gender,
							content:this.model.content,
							phone:this.model.phone,
							wechat:this.model.wechat,
							qq:this.model.qq
						},
						success: (res) => {
							if(res.data.code == '1'){
								this.$refs.uToast.show({
									title: '发起约拍成功',
									type: 'success'
								})
								setTimeout(()=>{
									uni.switchTab({
										url:'yuepai'
									})
								},2000)
								
							}else if(res.data.code=='0'){
								this.$refs.uToast.show({
									title: '网络开了小差',
									type: 'error'
								})
							}
						}
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.user {
		display: flex;
		align-items: center;
		padding: 20rpx;

		.name {
			margin-left: 20rpx;
		}
	}

	.info {
		.input {
			padding: 20rpx;
		}
	}

	.submit {
		width: 100%;
		position: fixed;
		bottom: 0;
		height: 100rpx;
		text-align: center;
		display: grid;
		background: #554d84;
		align-items: center;

		.text {
			color: white;
		}
	}
</style>
